<?php

namespace App\Http\Middleware;

use App\Utils\AppResult;
use App\Utils\Control\AuthUser;
use Closure;

class ApiSign
{
    // 日志模块名称
    const LOG_MODULE = 'ApiSign';

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next){
        $path = $request->path();// 当前请求地址
        if (!in_array($path,self::whiteList())) {
            //验证登录
            if (!AuthUser::getInstance()->check()) {
                return AppResult::response400('未登录，令牌失效，请稍后重试！');
            }
        }

        $response = $next($request);

        return $response;
    }

    //白名单
    public function whiteList(){
        return [
            'api/framework/passport/login',
        ];
    }
}